/*
* Copyright (c) 2016 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
*/
package com.hyyt.shopjsp.basic.service.imp;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.hyyt.shopjsp.basic.vo.BasicCustomerVo;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.hyyt.shopjsp.basic.dao.BasicCustomerDAO;
import com.hyyt.shopjsp.basic.pojo.BasicCustomer;
import com.hyyt.shopjsp.basic.service.IBasicCustomerService;
/**
* basic_customer, BASIC_客户表
 *
 * @author Robot 14-5-7 上午10:19
 */
@Service
public class BasicCustomerService implements IBasicCustomerService {
    private static  final Logger logger = Logger.getLogger(IBasicCustomerService.class);

    @Resource
    private BasicCustomerDAO basicCustomerDAO;

    /**
     * 保存BASIC_客户表
     *
     * @param basicCustomer BASIC_客户表
     * @return 保存后的BASIC_客户表
     */
    @Override
    public void saveBasicCustomer(BasicCustomer basicCustomer) {
        basicCustomerDAO.insert(basicCustomer);
    }

    /**
     * 更新BASIC_客户表
     *
     * @param basicCustomer BASIC_客户表
     * @return 更新后的BASIC_客户表
     */
    @Override
    public void updateBasicCustomer(BasicCustomer basicCustomer) {
        basicCustomerDAO.update(basicCustomer);
    }

    /**
     * 更新BASIC_客户表中的冻结状态
     *
     * @param param
     * @return 更新后的BASIC_客户表
     */
    @Override
    public void updateBasicCustomerByCustomerId(Map<String, Object> param) {
        basicCustomerDAO.update("updateBasicCustomerByCustomerId",param);
    }

    /**
     * 删除指定ID的BASIC_客户表
     *
     * @param id BASIC_客户表ID
     */
    @Override
    public void deleteBasicCustomer(Integer id) {
        basicCustomerDAO.delete(id);
    }

    /**
     * 删除指定ID集合的BASIC_客户表
     *
     * @param ids BASIC_客户表ID集合
    */
    public void deleteBasicCustomer(Collection<Integer> ids){
        basicCustomerDAO.batchDelete(ids);
    }

    /**
     * 根据ID加载一个BASIC_客户表
     *
     * @param id BASIC_客户表ID
     * @return BASIC_客户表
     */
    @Override
    public BasicCustomer loadBasicCustomer(Integer id) {
        return basicCustomerDAO.load(id);
    }

    /**
     * 加载BASIC_客户表——供微信模块调用
     *
     * @param params 查询参数，为key-value形式
     * @return BASIC_客户表集合
     */
    @Override
    public BasicCustomer loadBasicCustomerByWxUserOpenId(Map<String, Object> params) {
        return basicCustomerDAO.load("loadBasicCustomerByWxUserOpenId",params);
    }

    /**
     * 根据ID自定义加载一个BASIC_客户表
     *
     * @param params BASIC_客户表ID
     * @return BASIC_客户表
     */
    @Override
    public List<Map<String, Object>> queryCollectionByCustomerId(Map<String, Object> params) {
        return basicCustomerDAO.query("queryCollectionByCustomerId",params);
    }

    /**
    * 查询所有的BASIC_客户表，通常有最多取30000条记录的限制
    *
    * @return 所有的BASIC_客户表，通常有最多取30000条记录的限制
    */
    @Override
    public List<BasicCustomer> queryAllBasicCustomer() {
        return basicCustomerDAO.queryAll();
    }

    /**
     * 查询BASIC_客户表
     *
     * @param params 查询参数，为key-value形式
     * @return BASIC_客户表集合
     */
    @Override
    public List<BasicCustomer> queryBasicCustomer(Map<String, Object> params) {
        return basicCustomerDAO.query(params);
    }

    /**
     * 查询BASIC_客户表
     *
     * @param params   查询参数，没有则传null,分页参数key为“sortColumns”
     * @param startRow 起始行数（不含起始行的数据）
     * @param rowSize  要查询记录数
     * @return BASIC_客户表集合
     */
    @Override
    public List<BasicCustomer> queryBasicCustomer(Map<String, Object> params, int startRow, int rowSize) {
        return basicCustomerDAO.query(params, startRow, rowSize);
    }

    /**
     * 自定义查询BASIC_客户表
     *
     * @param params   查询参数，没有则传null,分页参数key为“sortColumns”
     * @param startRow 起始行数（不含起始行的数据）
     * @param rowSize  要查询记录数
     * @return BASIC_客户表集合
     */
    @Override
    public List<Map<String, Object>> queryBasicCustomerByCustomerId(Map<String, Object> params, int startRow, int rowSize) {
        return basicCustomerDAO.query("queryBasicCustomerByCustomerId",params, startRow, rowSize);
    }

    /**
     * 统计BASIC_客户表
     *
     * @param params 查询参数，没有则传null,分页参数key为“sortColumns”
     * @return 结果集记录数
     */
    @Override
    public int countBasicCustomer(Map<String, Object> params) {
        return basicCustomerDAO.count(params);
    }

    /**
     * 查询出该会员的返利金额
     * @param param
     */
	@Override
	public List<BasicCustomer> querySum(Map<String, Object> param) {
		return basicCustomerDAO.query("querySum", param);
	}

	/**
	 * 统计分销返利
	 * @param param
	 * @return
	 */
	@Override
	public int countReturnAmount(Map<String, Object> param) {
		return basicCustomerDAO.count("countReturnAmount", param);
	}

	/**
	 * 查询分销返利
	 * @param param
	 * @param pageRecordBeginIndex
	 * @param pageSize
	 * @return
	 */
	@Override
	public List<BasicCustomer> queryReturnAmount(Map<String, Object> param,int pageRecordBeginIndex, int pageSize) {
		return basicCustomerDAO.query("queryReturnAmount", param,pageRecordBeginIndex,pageSize);
	}

    /**
     * 会员销售信息统计列表
     * @param params
     * @param startRow
     * @param rowSize
     * @return
     */
    @Override
    public List<BasicCustomerVo> queryCustomerStatistics(Map<String, Object> params, int startRow, int rowSize) {
        return basicCustomerDAO.query("queryCustomerStatistics",params, startRow, rowSize);
    }

    /**
     * 导出会员销售统计excel
     * @param params
     * @return
     */
    @Override
    public List<BasicCustomerVo> queryCustomerStatistics(Map<String, Object> params) {
        return basicCustomerDAO.query("queryCustomerStatistics",params);
    }
    /**
     * 会员销售统计数量
     * @param params
     * @return
     */
    @Override
    public int countCustomerStatistics(Map<String, Object> params) {
        return basicCustomerDAO.count("countCustomerStatistics",params);
    }

}
